<template>
  <div>
    <span class="formTitle">
      <i class="vertical-bar"></i>定价引擎任务页面
    </span>
    <el-form :model="blockForm" ref="engineFormRef" label-width="200px" label-position="right">
      <el-row :gutter="30">
        <el-col :span="6">
          <el-form-item label="任务名称：" prop="taskName">
            <el-input v-model="blockForm.taskName" maxlength="32" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="定价编号：" prop="pricingCode">
            <el-input v-model="blockForm.pricingCode" maxlength="32" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="数据日期：" prop="dataDate">
            <el-input v-model="blockForm.dataDate"
            maxlength="32" disabled></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="6">
          <el-form-item label="运行状态：" prop="status">
            <el-select v-model="blockForm.status" style="width:100%" placeholder="请选择">
              <el-option
                v-for="item in statusOption"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <div style="text-align:center;padding:10px">
        <el-button size="mini" @click="searchFunc">查询</el-button>
        <el-button size="mini" @click="blockForm.status = ''">重置</el-button>
      </div>
    </el-form>

    <el-row class="container">
      <el-col style="margin-right:10px;" class="content-left">
        <upper-template :searchIcon="false" :configIcon="false">
          <!-- 操作按钮区 -->
          <template slot="buttonArea">
            <el-button @click="blockquery()">查询结果</el-button>
            <el-button @click="toRecord()">执行记录</el-button>
            <el-button @click="toSubRecord()">子任务</el-button>
            <el-button @click="goBack()">返回</el-button>
          </template>
        </upper-template>
      </el-col>
    </el-row>
    <el-table
      ref="blockModelTable"
      :data="blockModelData"
      style="width: 100%"
      @row-click="authorizeModelFor"
    >
      <el-table-column width="55" type="selection"  />
      <el-table-column prop="tableName" label="表名称" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column prop="blockSize" label="块大小" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column prop="dataDate" label="数据日期" 
      :formatter="formatterTime" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column prop="startAccount" label="开始编号" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column prop="endAccount" label="结束编号" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column prop="successNum" label="成功记录数" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column prop="failNum" label="失败记录数" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column prop="startTm" label="开始时间" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column prop="endTm" label="结束时间" :show-overflow-tooltip="true"></el-table-column>
      <el-table-column prop="status" label="运行状态" :show-overflow-tooltip="true"></el-table-column>
    </el-table>
    <!-- 分页插件 -->
    <pagination
      @size-change="blockhandleSizeChange"
      @current-change="blockhandleCurrentChange"
      :current-page="blockForm.page"
      :page-size="blockForm.size"
      @refresh="searchFunc"
      :total="total"
    ></pagination>
  </div>
</template>

<script>
import moment from "moment";
import { getDict } from "@/api/getDict";
import { pricingTask } from "@/api/index";
export default {
  props: {
    enginePricingCode: {
      type: String,
      default: () => {
        "";
      }
    }
  },
  components: {},
  data() {
    return {
      //引擎任务页面
      total: 0,
      positionOptions: {},
      statusOption: {},
      blocktitleName: "引擎任务",
      blockModelData: [],
      blockForm: {
        taskName: "异常定价任务",
        pricingCode: "",
        dataDate: "",
        status: "",
        page: 1,
        size: 15
      },
      block: false,
      //定价子任务表单数据
      total: null,
      subRecordModelData: []
      //定价子任务界面上方数据
    };
  },
  computed: {},
  created() {
    this.getstatus("ftp_pricing_task_status");
    //通过传过来的参数进行数据查询
    this.initParams();
 
  },
  methods: {
    initParams() {
      let params = {
        pricingCode: this.enginePricingCode
      };
      pricingTask.toBlock(params).then(res => {
        if (res.code == 200) {
          this.blockForm.pricingCode = res.data.pricingRecord.pricingCode;
          this.blockForm.dataDate = moment(
            res.data.pricingRecord.dataDate
          ).format("YYYY-MM-DD");
          this.blockForm.status = res.data.pricingRecord.status;
          this.blockForm.taskCode = res.data.pricingRecord.taskCode;
          //查询数据
             this.searchFunc();
        }
      });
    },
    getstatus(data) {
      getDict(data).then(res => {
        if (res.code == 200) {
          this.statusOption = res.datas;
        } else {
          this.$message.error(res.message);
        }
      });
    },
    authorizeModelFor(row) {
      if (this.$refs.blockModelTable) {
        this.$refs.blockModelTable.clearSelection();
      }
      this.$refs.blockModelTable.toggleRowSelection(row, true);
    },
    //列表查询
    searchFunc() {
      let pagedata = this.blockForm;
      pricingTask.findAllBlock(pagedata).then(res => {
        console.log(res, "跳转引擎任务的时候chaxundaodeshujv==============");
        if (res.code == 200) {
          this.blockModelData = res.datas.rows;
        }
        console.log(this.blockModelData, "blockModelData");
      });
    },
    blockhandleSizeChange(val) {
      this.blockForm.size = val;
      this.searchFunc();
    },
    blockhandleCurrentChange(val) {
      this.blockForm.page = val;
      this.searchFunc();
    },
    //查看结果数据
    blockquery() {
        let selections = this.$refs.blockModelTable.selection;
        if(selections.length !=1){
           return this.$message.warning("请选择一条数据进行操作!") ;
        }
        this.$emit("toBlockDetail",selections[0].blockId);

    },
    // 执行记录
    toRecord() {
      this.$emit("toExecuteTask");
    },
    toSubRecord() {
      let params = {
        taskName: this.blockForm.taskName,
        pricingCode: this.blockForm.pricingCode,
        dataDate: this.blockForm.dataDate,
        taskCode: this.blockForm.taskCode
      };
      this.$emit("catSubTask", params);
    },
    goBack() {
      this.$emit("closeExMonitor");
    },
   //事件转换
    formatterTime(row, column) {
      let ele = row[column.property];
      if (ele) return moment(ele).format("YYYY-MM-DD HH:mm:ss");
      else return "-";
    },

  }
};
</script>

<style  lang="scss" scoped>

.formTitle {
  font-size: 14px;
  font-weight: 700;
  display: block;
  margin-bottom: 10px;
}
</style>